<?php

namespace Admin\Controller;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/10 0010
 * Time: 13:59
 */

class ManagerController extends CommonController
{
    //公司级
    public function company_list()
    {
        //首先根据登陆的id查询其等级，和负责的风险点
        $user_id=$_SESSION['userid'];

        $level_id=$_SESSION['level_id'];
        $object_ids=$_SESSION['object_ids'];


        if($level_id==1)
        {
        //查询具有危险源为公司级的风险点id和名称
        $sql = " select id,  name from   xc_danger where id=(select danger_id from xc_object where  object_level_id=1 and status=1)";

        $Data = M('danger'); //实例化Data数据模型
        $list = $Data->query($sql);
        if (!empty($list)) {
            foreach ($list as $k => $v) {
                //根据风险点ID查询，风险等级为1的
                //  $list[$k]['type_name'] = M('ObjectType')->where(['id' => $v['type_id']])->getField('name');
                $map['danger_id'] = $v['id'];
                $map['object_level_id'] = '1';
                $map['status'] = '1';
                $res2 = M('object')->where($map)->select();
                $list[$k]['voo'] = $res2;
            }
        }
          $this->assign('list', $list);
            $this->display('company_list');

        }
        else
        {

            $this->error('无权限！',U('Test/test_list'));

        }



    }

    public function company_do()
    {
        if (IS_POST) {
           /* $post = I('post.');
            $msg_id = $post['msg_id'];
            $post['create_time'] = time();
            $res = M('Msg')->where(['msg_id' => $msg_id])->save($post);
            if (empty($res)) {
                $this->error('修改失败！', U('Msg/edit_msg'));
            }
            $this->success('修改成功！', U('Msg/msg_list'));*/
        }
        if (IS_GET) {
            $object_id = $_GET['object_id'];
            $info = M('Object')->where(['object_id' => $object_id])->find();
            $this->assign('info', $info);
            $this->display('company_do');
        }
    }

//专业级
    public function part_list()
    {
        //部门表
        $list = $this->lists('part', 'status = 1', ' id asc');
        if (!empty($list)) {
            foreach ($list as $k => $v) {
                //查询部门级风险点，等级为2的危险源,并且责任单位(对应车间，这里为专业级)属于对应专业级的ID
                $sql = " select id,  name from   xc_danger where id in (select danger_id from xc_object where  object_level_id=2 and status=1)";
                $Data = M('danger'); //实例化Data数据模型
                $res2 = $Data->query($sql);
                $list[$k]['voo'] = $res2;
                /*  if(  $list[$k]['voo'])
                   {
                       foreach (  $list[$k]['voo'] as $k => $v)
                       {
                           //查询部门级风险点下风险点下对应的危险源为2级的 object_level_id为2的危险源
                           //根据风险点ID查询，风险等级为2的无数据2的
                       }
                   }*/


            }

            /*
            //车间表
            $res2 = M('workshop')->where(['part_id' => $v['id']])->select();
            $list[$k]['voo'] = $res2;
            */
        }

        // $sql= "  select danger_id from xc_object where  object_level_id=2 and status=1 and danger_id=".$v['id'];
        $sql = "  select danger_id ,object_id,name from xc_object where  object_level_id=2 and status=1 and danger_level_id=2  ";
        $Data = M('danger'); //实例化Data数据模型
        $res3 = $Data->query($sql);
        $this->assign('test', $res3);// 赋值数据集
        $this->assign('list', $list);// 赋值数据集


        $this->display('part_list');

        /*
    $sql='select  *  from xc_workshop where status = 1';
   // and part_id =';
    //$sql= $sql.$vo['id'];
    $Data = M('workshop'); //实例化Data数据模型
    $res2= $Data->query($sql);
    // $res2 = $this->lists('workshop', $where, ' id asc');
    if ($res2) {
        foreach ($res2 as $k1 => $sub) {
            // $res2[$k1]['name'] = M('workshop')->where(['part_id' => $v['id']])->getField('name');
            echo  count($res2);
        }
        */
        //  var_dump($res2);

        //    $this->assign('res2', $res2);

        /*
                $list = $this->lists('part','status = 1', ' id asc');
                if (!empty($list)) {
                    foreach ($list as $k=>$v) {
                        //  $list[$k]['type_name'] = M('ObjectType')->where(['id' => $v['type_id']])->getField('name');
                        //$list[$k]['danger_name'] =  M('danger')->where(['id' => $v['danger_id']])->getField('name');
                    }
                }
               $this->assign('list', $list);
        */
    }


    //车间级
    public function workshop_list()
    {
        //车间表
        $list = $this->lists('workshop', 'status = 1', ' id asc');
        if (!empty($list)) {
            foreach ($list as $k => $v) {
                //查询部门级风险点，等级为2的危险源,并且责任单位(对应车间，这里为专业级)属于对应专业级的ID
                $sql = " select id,  name from   xc_danger where id in (select danger_id from xc_object where  object_level_id=3 and status=1)";
                $Data = M('danger'); //实例化Data数据模型
                $res2 = $Data->query($sql);
                $list[$k]['voo'] = $res2;
            }
            $sql = "  select danger_id ,object_id,name from xc_object where  object_level_id=3 and status=1  ";
            $Data = M('danger'); //实例化Data数据模型
            $res3 = $Data->query($sql);
            $this->assign('test', $res3);// 赋值数据集
            $this->assign('list', $list);// 赋值数据集


                $this->display('workshop_list');

            }
        }

}

